package com.baomidou.springboot.config;

import java.time.LocalDateTime; 
import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

@Component
public class MyMetaObjectHandler  implements MetaObjectHandler {
	private final static Logger logger = LoggerFactory.getLogger(MyMetaObjectHandler.class);
	    
	    // 新增的时候自动填充
	    @Override
	    public void insertFill(MetaObject metaObject) {
	    	logger.info("start insert fill ....");
	        this.setFieldValByName("registrTime",LocalDateTime.now(),metaObject);
	        this.setFieldValByName("donatTime",LocalDateTime.now(),metaObject);
	        this.setFieldValByName("createTime",LocalDateTime.now(),metaObject);
	    }

		// 更新的税后自动填充
	    @Override
	    public void updateFill(MetaObject metaObject) {
	    	logger.info("start update fill ....");
	        this.setFieldValByName("lastUpdateTime", LocalDateTime.now(),metaObject);
	        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
	    }
}
